/* (C) 2007-2009 caitong Limited
 * (C) 2009-2012  limited
 *
 * Authors:
 * legs.ant.king@gmail.com


   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
#include "../include/InitVariable.h"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
using namespace std;
void getYN();
int Inputstatus=0;
static char iGetIn[1]={0};
void getIN(char *iGetIn,char iCompasion[][50],int InNum);
void iFuZhiParm(char iArgument[][50],char iCompasion[][50],int ParmNum);

void iLastInitVariable(char iArgument[][50],char iCompasion[][50])
{
	const int iParmCount=ArgumentCount();
	for(int i = 0 ; i < iParmCount ; i++)
	{
		if(strcmp(iArgument[i],"")==0)
		{
			iFuZhiParm(iArgument,iCompasion,i);
		}
	}
}

void getYN()
{
	char  iInput;
	cin>>iInput;
switch(iInput)
	{
		case 'Y':
		{
			Inputstatus=1;
			break;
		}
		case 'N':
		{
			exit(0);
		}
		default:
		{
			cout<<"Input Error Please again input .\n";
			getYN();
		}
	}
}

void getIN(char *iGetIn,char iCompasion[][50],int InNum)
{
	printf("Please Input %s :",iCompasion[InNum]);
	char iInput[10]={0};
	cin>>iInput;
	printf("\n");
	strcpy(iGetIn,iInput);
}

void iFuZhiParm(char iArgument[][50],char iCompasion[][50],int ParmNum)
{
	if(strcmp(iCompasion[ParmNum],"sentmsg") == 0)
	{
		strcpy(iArgument[ParmNum],"0");
	}
	if(strcmp(iCompasion[ParmNum],"programsleep")==0)
	{
		strcpy(iArgument[ParmNum],"3600");
	}
	if(strcmp(iCompasion[ParmNum],"user")==0)
	{
		strcpy(iArgument[ParmNum],"root");
	}
	if(strcmp(iCompasion[ParmNum],"MaxWarningValue")==0)
	{
		strcpy(iArgument[ParmNum],"4000");
	}
	if(strcmp(iCompasion[ParmNum],"hostname")==0)
	{
		strcpy(iArgument[ParmNum],"localhost"); 
	}
	if(strcmp(iCompasion[ParmNum],"port")==0)
	{
		strcpy(iArgument[ParmNum],"3306"); 
	}
	if(strcmp(iCompasion[ParmNum],"socket")==0)
	{
		strcpy(iArgument[ParmNum],"/tmp/mysql.sock");
	}
	if(strcmp(iCompasion[ParmNum],"dbname")==0)
	{
		strcpy(iArgument[ParmNum],"test");
	}
	if(strcmp(iCompasion[ParmNum],"daemon") == 0)
	{
		strcpy(iArgument[ParmNum],"0");
	}
	if(strcmp(iCompasion[ParmNum],"logfile")==0)
	{
		strcpy(iArgument[ParmNum],"repmsg.log");
	}
	if(strcmp(iCompasion[ParmNum],"MaxWarningValue")==0)
	{
		strcpy(iArgument[ParmNum],"4000");
	}
	if(strcmp(iCompasion[ParmNum],"errsentperf")==0)
	{
		strcpy(iArgument[ParmNum],"10");
	}
	if(strcmp(iCompasion[ParmNum],"sleeptime")==0)
	{
		strcpy(iArgument[ParmNum],"30");
	}
	if(strcmp(iCompasion[ParmNum],"warsentperf")==0)
	{
		strcpy(iArgument[ParmNum],"20");
	}
	if(strcmp(iCompasion[ParmNum],"sentcount")==0)
	{
		strcpy(iArgument[ParmNum],"3");
	}
	if(strcmp(iCompasion[ParmNum],"sendto") ==0 )
	{
		strcpy(iArgument[ParmNum],"0");
	}
	if(strcmp(iCompasion[ParmNum],"remail")==0)
	{
		strcpy(iArgument[ParmNum],"DbaTeam@gmail.com");
	}
	if(strcmp(iCompasion[ParmNum],"email")==0)
	{
		strcpy(iArgument[ParmNum],"DbaTeam@gmail.com");
	}
	if(strcmp(iCompasion[ParmNum],"ecount") ==0)
	{
		strcpy(iArgument[ParmNum],"20");
	}
	if(strcmp(iCompasion[ParmNum],"sphone")==0)
	{
		cout<<"not specify Sent message phone whether continue (Y/N) || ";
		getYN();
		if(Inputstatus==1)
		{
			getIN(iGetIn,iCompasion,ParmNum);
			strcpy(iArgument[ParmNum],iGetIn);
		}
	}
	if(strcmp(iCompasion[ParmNum],"phonepwd")==0)
	{
		cout<<"not specify Sent message phone password whether continue (Y/N) || ";
		getYN();
		if(Inputstatus==1)
		{
			getIN(iGetIn,iCompasion,ParmNum);
			strcpy(iArgument[ParmNum],iGetIn);
		}
	}
	if(strcmp(iCompasion[ParmNum],"phone")==0)
	{
		cout<<"not specify Sent message to phone , at the least one phone number whether continue (Y/N) || ";
		getYN();
		if(Inputstatus==1)
		{
			getIN(iGetIn,iCompasion,ParmNum);
			strcpy(iArgument[ParmNum],iGetIn);
		}
	}
}

int GetMatachChar(char iCompasion[][50],char *GetIn)
{
	for(int i=0;i<ArgumentCount();i++)
	{
		if(strcmp(iCompasion[i],GetIn)==0)
		{
			return i;
			break;
		}
	}
}




